package com.example.flyweight;

import com.example.flyweight.content.TreeType;

import java.util.HashMap;
import java.util.Map;

public class TreeFactory {
    private static final Map<Integer, TreeType> treeTypeMap = new HashMap<>();

    public static TreeType getTreeType(int id, String name, String color, int size) {
        if (treeTypeMap.containsKey(id)) {
            return treeTypeMap.get(id);
        } else {
            TreeType treeType = new TreeType(name, color, size);
            treeTypeMap.put(id, treeType);
            System.out.println("创建新类型");

            return treeType;
        }
    }

}
